package com.itheima.controller;
import com.itheima.pojo.*;
import com.itheima.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RequestMapping("/clazzs")
@RestController
public class ClazzController {
    @Autowired
    private ClazzService clazzService;
    @GetMapping
    public Result page(ClazzQueryParam param){
        log.info("查询班级请求参数: {}", param);
        PageBean pageBean = clazzService.clazzList(param);
        return Result.success(pageBean);
    }
    @PostMapping
    public Result add(@RequestBody Clazz clazz) {
        System.out.println("添加班级: " + clazz);
        clazzService.add(clazz);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) {
        System.out.println("根据ID查询班级数据: " + id);
        Clazz clazz = clazzService.selectById(id);
        return Result.success(clazz);
    }
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        System.out.println("修改班级: " + clazz);
        clazzService.update(clazz);
        return Result.success();
    }
    @DeleteMapping("/{id}")
    public Result delete( @PathVariable Integer id)  {
        System.out.println("根据ID删除班级: " + id);
        clazzService.delete(id);
        return Result.success();
    }
    @GetMapping("/list")
    public  Result select () {
        System.out.println("查询所有班级数据: " );
        List<Clazz> clazzList = clazzService.selectAll();
        return Result.success(clazzList);
    }
}
